import numpy as np
import torch
import uvicorn
from typing import *
from utils import *
from fastapi import FastAPI
from pydantic import BaseModel


# -*- coding: utf-8 -*-
# @Time : 2022/10/26 0:03
# @Author : renyumeng
# @Email : 2035328756@qq.com
# @File : app.py
# @Project : pythonFile
def dataLoadJson(data):
    l = len(data)
    S = []
    S1 = []
    S2 = []
    S3 = []
    S4 = []
    for i in range(l):
        S.append(eval(data[i]["bpi"]))
        S1.append(eval(data[i]["pi"]))
        S2.append(eval(data[i]["zuv"]))
        # S3.append(eval(data[i]["otw"]))
        S4.append(eval(data[i]["scms"]))
    num_0 = 0
    num_n = 0
    for j in range(len(S)):
        num_n += 1
        if j >= 1 and S[j] <= 0:
            num = S[j - 1]
            S[j] = num
        if j >= 1 and abs(S[j] - S[j - 1]) >= 1:
            num_m = S[j]
            S[j] = S[j - 1]
            num_0 += 1
        if num_0 >= 4:
            S[j - 1], S[j] = num_m, num_m
            num_0 = 0
        if num_n >= 4:
            num_0 = 0
            num_n = 0

    num_0 = 0
    num_n = 0
    for k in range(len(S1)):
        num_n += 1
        if k >= 1 and S1[k] <= 0:
            num = S1[k - 1]
            S1[k] = num
        if k >= 1 and abs(S1[k] - S1[k - 1]) >= 1:
            num_m = S1[k]
            S1[k] = S1[k - 1]
            num_0 += 1
        if num_0 >= 4:
            S1[k - 1], S1[k] = num_m, num_m
            num_0 = 0
        if num_n >= 4:
            num_0 = 0
            num_n = 0
    if l % 10000 != 0:
        x = l % 10000
        s = S[len(S) - 10000:len(S)]
        s1 = S1[len(S1) - 10000:len(S1)]
        s2 = S2[len(S2) - 10000:len(S2)]
        # s3 = S3[len(S3) - 10000:len(S3)]
        s4 = S4[len(S4) - 10000:len(S4)]
        del S[len(S) - x:len(S)]
        del S1[len(S1) - x:len(S1)]
        del S2[len(S2) - x:len(S2)]
        # del S3[len(S3) - x:len(S3)]
        del S4[len(S4) - x:len(S4)]
        S.extend(s), S1.extend(s1), S2.extend(s2), S4.extend(s4)
    results = []
    results.append(S)
    results.append(S1)
    results.append(S2)
    # results.append(S3)
    results.append(S4)
    l = len(S)
    inputs = np.array(results)
    inputs = inputs.T
    inputs = inputs.reshape(1, 4 * l)
    return inputs, 4 * l
